package cn.legend.travel.ask.dao.persist.repository.impl;

import cn.legend.travel.ask.dao.persist.mapper.AnswerMapper;
import cn.legend.travel.ask.dao.persist.repository.AnswerRepository;
import cn.legend.travel.ask.pojo.entity.Answer;
import cn.legend.travel.ask.pojo.entity.Ask;
import cn.legend.travel.ask.pojo.vo.AnswerStandardVO;
import cn.legend.travel.common.pojo.authentication.CurrentPrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class AnswerRepositoryImpl implements AnswerRepository {
    @Autowired
    private AnswerMapper answerMapper;
    @Override
    public int addLikes(Long answerId) {
        return answerMapper.addLikes(answerId);
    }

    @Override
    public Answer getAnswer(Long answerId) {
        return answerMapper.selectById(answerId);
    }

    @Override
    public int cancelLikes(Long answerId) {
        return answerMapper.cancelLikes(answerId);
    }

    @Override
    public int addView(Long answerId) {
        return answerMapper.addView(answerId);
    }

    @Override
    public int report(Long answerId) {
        return answerMapper.report(answerId);
    }

    @Override
    public int addNewAnswer(Answer answer) {
        return answerMapper.insert(answer);
    }
    @Override
    public AnswerStandardVO getBestAsk(Long questionId) {
        return answerMapper.getBestAsk(questionId);
    }

    @Override
    public AnswerStandardVO getBestAsk(Long questionId, CurrentPrincipal currentPrincipal) {
        return answerMapper.getBestAskAndUserId(questionId,currentPrincipal.getId());
    }
}
